CXX = g++
CXXFLAGS = -std=c++14 -Wall -g -O0

TARGET = server
SRCDIR = ./code#源码位置
BUILDDIR = build#目标文件位置

#源文件
SRCS = $(wildcard $(SRCDIR)/log/*.cpp) $(wildcard $(SRCDIR)/pool/*.cpp) $(wildcard $(SRCDIR)/timer/*.cpp) \
       $(wildcard $(SRCDIR)/http/*.cpp) $(wildcard $(SRCDIR)/server/*.cpp) \
       $(wildcard $(SRCDIR)/buffer/*.cpp) $(SRCDIR)/main.cpp

#目标文件(对SRCS进行pattern匹配,然后替换)
#$(SRCDIR)/log/*.cpp -> $(BUILDDIR)/log/*.o
#$(SRCDIR)/pool/*.cpp -> $(BUILDDIR)/pool/*.o
OBJS = $(patsubst $(SRCDIR)/%.cpp,$(BUILDDIR)/%.o,$(SRCS))


$(TARGET): $(OBJS)
	$(CXX) $(CXXFLAGS) $(OBJS) -o $(TARGET)  -lpthread -L/usr/lib64/mysql -lmysqlclient


#生成目标文件
$(BUILDDIR)/%.o:$(SRCDIR)/%.cpp | $(BUILDDIR)
	$(CXX) $(CXXFLAGS) -c $< -o $@

#创建build目录
$(BUILDDIR):
	mkdir -p $(BUILDDIR)
	mkdir -p $(BUILDDIR)/log
	mkdir -p $(BUILDDIR)/pool
	mkdir -p $(BUILDDIR)/timer
	mkdir -p $(BUILDDIR)/http
	mkdir -p $(BUILDDIR)/server
	mkdir -p $(BUILDDIR)/buffer

.PHONY:clean
clean:
	rm -rvf $(TARGET) $(BUILDDIR)
